package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         739,
		Discription: "每日温度",
		Level:       2,
		Labels: map[string]int{
			"栈":   1,
			"单调栈": 1,
		},
	})
}

func DailyTemperatures(temperatures []int) []int {
	n := len(temperatures)
	res := make([]int, n)
	s := make([]int, 0)
	for index, temp := range temperatures {
		for len(s) > 0 && temperatures[s[len(s)-1]] < temp {
			topIndex := s[len(s)-1]
			res[topIndex] = index - topIndex
			s = s[:len(s)-1]
		}
		s = append(s, index)
	}

	return res
}
